package com.abel.service.impl;

import com.abel.domain.contracts.EmailRequestContract;
import com.abel.manager.exception.EmailSendException;
import com.abel.service.EmailService;
import com.abel.service.helper.EmailSender;

public class EmailServiceImpl implements EmailService{

	
	private String smtpHost;
	
	private String fromAddress;
	
	private String messageTemplate;
	
	private String emailSubject;
	
	@Override
	public void sendEmail(EmailRequestContract requestContract)
			throws EmailSendException {
		
		EmailSender emailSender = new EmailSender();
		try {
			emailSender.setSmtpHost(this.smtpHost);
			emailSender.sendEmail(this.fromAddress, 
					requestContract.getTo(), 
					requestContract.getSubject(), 
					requestContract.getMessage());
		} catch (Exception e) {
			
			e.printStackTrace();
			throw new EmailSendException("Exception while sending email. Smtp=" + this.smtpHost + " -from=" + this.fromAddress + " -to=" + requestContract.getTo(),e);
		}
		
	}

	@Override
	public void setSmtpHost(String smtpHost) {
		this.smtpHost = smtpHost;
		
	}

	@Override
	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
		
	}

	@Override
	public void setMessageTemplate(String messageTemplate) {
		this.messageTemplate = messageTemplate;
	}

	@Override
	public void setEmailSubject(String emailSubject) {
		this.emailSubject = emailSubject;
		
	}

	/**
	 * @return the smtpHost
	 */
	public String getSmtpHost() {
		return smtpHost;
	}

	/**
	 * @return the fromAddress
	 */
	public String getFromAddress() {
		return fromAddress;
	}

	/**
	 * @return the messageTemplate
	 */
	public String getMessageTemplate() {
		return messageTemplate;
	}

	/**
	 * @return the emailSubject
	 */
	public String getEmailSubject() {
		return emailSubject;
	}
}
